{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "authorship_tag": "ABX9TyPJXo2vbVsyw/Z68l9mWRtG",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/nceder/qpb4e/blob/main/code/Chapter%2002/Chapter_02.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# 2.2 Getting started with Python and Colaboratory"
      ],
      "metadata": {
        "id": "OEuZxfjDr5aH"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# 2.3 Hello world"
      ],
      "metadata": {
        "id": "I6AD944jzBZQ"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# After running the first time, experiment with printing different strings (in quotes)\n",
        "print(\"Hello, World!\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "jLOqTf6-zGeg",
        "outputId": "7ab0c680-490d-42bd-ac11-bb9487743216"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Hello, World\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# this cell will raise a syntax error\n",
        "print(\"Hello, World!\""
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 106
        },
        "id": "9Bi90QbW0_T-",
        "outputId": "c2eedfa2-1127-4f3e-bd59-7f692500aac5"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "error",
          "ename": "SyntaxError",
          "evalue": "incomplete input (<ipython-input-1-36a2ef7a0a32>, line 2)",
          "traceback": [
            "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-1-36a2ef7a0a32>\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m    print(\"Hello, World!\"\u001b[0m\n\u001b[0m                         ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m incomplete input\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# 2.4 Using `help` and `dir` to explore Python"
      ],
      "metadata": {
        "id": "5u6VfSQkzHER"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "help()"
      ],
      "metadata": {
        "id": "7Fioddm2G3kg"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "x = 2\n",
        "help(x)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "0Ev0XXazzSaK",
        "outputId": "460ae5ba-f108-4ebb-b4ee-270b00904550"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Help on int object:\n",
            "\n",
            "class int(object)\n",
            " |  int([x]) -> integer\n",
            " |  int(x, base=10) -> integer\n",
            " |  \n",
            " |  Convert a number or string to an integer, or return 0 if no arguments\n",
            " |  are given.  If x is a number, return x.__int__().  For floating point\n",
            " |  numbers, this truncates towards zero.\n",
            " |  \n",
            " |  If x is not a number or if base is given, then x must be a string,\n",
            " |  bytes, or bytearray instance representing an integer literal in the\n",
            " |  given base.  The literal can be preceded by '+' or '-' and be surrounded\n",
            " |  by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.\n",
            " |  Base 0 means to interpret the base from the string as an integer literal.\n",
            " |  >>> int('0b100', base=0)\n",
            " |  4\n",
            " |  \n",
            " |  Built-in subclasses:\n",
            " |      bool\n",
            " |  \n",
            " |  Methods defined here:\n",
            " |  \n",
            " |  __abs__(self, /)\n",
            " |      abs(self)\n",
            " |  \n",
            " |  __add__(self, value, /)\n",
            " |      Return self+value.\n",
            " |  \n",
            " |  __and__(self, value, /)\n",
            " |      Return self&value.\n",
            " |  \n",
            " |  __bool__(self, /)\n",
            " |      True if self else False\n",
            " |  \n",
            " |  __ceil__(...)\n",
            " |      Ceiling of an Integral returns itself.\n",
            " |  \n",
            " |  __divmod__(self, value, /)\n",
            " |      Return divmod(self, value).\n",
            " |  \n",
            " |  __eq__(self, value, /)\n",
            " |      Return self==value.\n",
            " |  \n",
            " |  __float__(self, /)\n",
            " |      float(self)\n",
            " |  \n",
            " |  __floor__(...)\n",
            " |      Flooring an Integral returns itself.\n",
            " |  \n",
            " |  __floordiv__(self, value, /)\n",
            " |      Return self//value.\n",
            " |  \n",
            " |  __format__(self, format_spec, /)\n",
            " |      Default object formatter.\n",
            " |  \n",
            " |  __ge__(self, value, /)\n",
            " |      Return self>=value.\n",
            " |  \n",
            " |  __getattribute__(self, name, /)\n",
            " |      Return getattr(self, name).\n",
            " |  \n",
            " |  __getnewargs__(self, /)\n",
            " |  \n",
            " |  __gt__(self, value, /)\n",
            " |      Return self>value.\n",
            " |  \n",
            " |  __hash__(self, /)\n",
            " |      Return hash(self).\n",
            " |  \n",
            " |  __index__(self, /)\n",
            " |      Return self converted to an integer, if self is suitable for use as an index into a list.\n",
            " |  \n",
            " |  __int__(self, /)\n",
            " |      int(self)\n",
            " |  \n",
            " |  __invert__(self, /)\n",
            " |      ~self\n",
            " |  \n",
            " |  __le__(self, value, /)\n",
            " |      Return self<=value.\n",
            " |  \n",
            " |  __lshift__(self, value, /)\n",
            " |      Return self<<value.\n",
            " |  \n",
            " |  __lt__(self, value, /)\n",
            " |      Return self<value.\n",
            " |  \n",
            " |  __mod__(self, value, /)\n",
            " |      Return self%value.\n",
            " |  \n",
            " |  __mul__(self, value, /)\n",
            " |      Return self*value.\n",
            " |  \n",
            " |  __ne__(self, value, /)\n",
            " |      Return self!=value.\n",
            " |  \n",
            " |  __neg__(self, /)\n",
            " |      -self\n",
            " |  \n",
            " |  __or__(self, value, /)\n",
            " |      Return self|value.\n",
            " |  \n",
            " |  __pos__(self, /)\n",
            " |      +self\n",
            " |  \n",
            " |  __pow__(self, value, mod=None, /)\n",
            " |      Return pow(self, value, mod).\n",
            " |  \n",
            " |  __radd__(self, value, /)\n",
            " |      Return value+self.\n",
            " |  \n",
            " |  __rand__(self, value, /)\n",
            " |      Return value&self.\n",
            " |  \n",
            " |  __rdivmod__(self, value, /)\n",
            " |      Return divmod(value, self).\n",
            " |  \n",
            " |  __repr__(self, /)\n",
            " |      Return repr(self).\n",
            " |  \n",
            " |  __rfloordiv__(self, value, /)\n",
            " |      Return value//self.\n",
            " |  \n",
            " |  __rlshift__(self, value, /)\n",
            " |      Return value<<self.\n",
            " |  \n",
            " |  __rmod__(self, value, /)\n",
            " |      Return value%self.\n",
            " |  \n",
            " |  __rmul__(self, value, /)\n",
            " |      Return value*self.\n",
            " |  \n",
            " |  __ror__(self, value, /)\n",
            " |      Return value|self.\n",
            " |  \n",
            " |  __round__(...)\n",
            " |      Rounding an Integral returns itself.\n",
            " |      \n",
            " |      Rounding with an ndigits argument also returns an integer.\n",
            " |  \n",
            " |  __rpow__(self, value, mod=None, /)\n",
            " |      Return pow(value, self, mod).\n",
            " |  \n",
            " |  __rrshift__(self, value, /)\n",
            " |      Return value>>self.\n",
            " |  \n",
            " |  __rshift__(self, value, /)\n",
            " |      Return self>>value.\n",
            " |  \n",
            " |  __rsub__(self, value, /)\n",
            " |      Return value-self.\n",
            " |  \n",
            " |  __rtruediv__(self, value, /)\n",
            " |      Return value/self.\n",
            " |  \n",
            " |  __rxor__(self, value, /)\n",
            " |      Return value^self.\n",
            " |  \n",
            " |  __sizeof__(self, /)\n",
            " |      Returns size in memory, in bytes.\n",
            " |  \n",
            " |  __sub__(self, value, /)\n",
            " |      Return self-value.\n",
            " |  \n",
            " |  __truediv__(self, value, /)\n",
            " |      Return self/value.\n",
            " |  \n",
            " |  __trunc__(...)\n",
            " |      Truncating an Integral returns itself.\n",
            " |  \n",
            " |  __xor__(self, value, /)\n",
            " |      Return self^value.\n",
            " |  \n",
            " |  as_integer_ratio(self, /)\n",
            " |      Return integer ratio.\n",
            " |      \n",
            " |      Return a pair of integers, whose ratio is exactly equal to the original int\n",
            " |      and with a positive denominator.\n",
            " |      \n",
            " |      >>> (10).as_integer_ratio()\n",
            " |      (10, 1)\n",
            " |      >>> (-10).as_integer_ratio()\n",
            " |      (-10, 1)\n",
            " |      >>> (0).as_integer_ratio()\n",
            " |      (0, 1)\n",
            " |  \n",
            " |  bit_count(self, /)\n",
            " |      Number of ones in the binary representation of the absolute value of self.\n",
            " |      \n",
            " |      Also known as the population count.\n",
            " |      \n",
            " |      >>> bin(13)\n",
            " |      '0b1101'\n",
            " |      >>> (13).bit_count()\n",
            " |      3\n",
            " |  \n",
            " |  bit_length(self, /)\n",
            " |      Number of bits necessary to represent self in binary.\n",
            " |      \n",
            " |      >>> bin(37)\n",
            " |      '0b100101'\n",
            " |      >>> (37).bit_length()\n",
            " |      6\n",
            " |  \n",
            " |  conjugate(...)\n",
            " |      Returns self, the complex conjugate of any int.\n",
            " |  \n",
            " |  to_bytes(self, /, length, byteorder, *, signed=False)\n",
            " |      Return an array of bytes representing an integer.\n",
            " |      \n",
            " |      length\n",
            " |        Length of bytes object to use.  An OverflowError is raised if the\n",
            " |        integer is not representable with the given number of bytes.\n",
            " |      byteorder\n",
            " |        The byte order used to represent the integer.  If byteorder is 'big',\n",
            " |        the most significant byte is at the beginning of the byte array.  If\n",
            " |        byteorder is 'little', the most significant byte is at the end of the\n",
            " |        byte array.  To request the native byte order of the host system, use\n",
            " |        `sys.byteorder' as the byte order value.\n",
            " |      signed\n",
            " |        Determines whether two's complement is used to represent the integer.\n",
            " |        If signed is False and a negative integer is given, an OverflowError\n",
            " |        is raised.\n",
            " |  \n",
            " |  ----------------------------------------------------------------------\n",
            " |  Class methods defined here:\n",
            " |  \n",
            " |  from_bytes(bytes, byteorder, *, signed=False) from builtins.type\n",
            " |      Return the integer represented by the given array of bytes.\n",
            " |      \n",
            " |      bytes\n",
            " |        Holds the array of bytes to convert.  The argument must either\n",
            " |        support the buffer protocol or be an iterable object producing bytes.\n",
            " |        Bytes and bytearray are examples of built-in objects that support the\n",
            " |        buffer protocol.\n",
            " |      byteorder\n",
            " |        The byte order used to represent the integer.  If byteorder is 'big',\n",
            " |        the most significant byte is at the beginning of the byte array.  If\n",
            " |        byteorder is 'little', the most significant byte is at the end of the\n",
            " |        byte array.  To request the native byte order of the host system, use\n",
            " |        `sys.byteorder' as the byte order value.\n",
            " |      signed\n",
            " |        Indicates whether two's complement is used to represent the integer.\n",
            " |  \n",
            " |  ----------------------------------------------------------------------\n",
            " |  Static methods defined here:\n",
            " |  \n",
            " |  __new__(*args, **kwargs) from builtins.type\n",
            " |      Create and return a new object.  See help(type) for accurate signature.\n",
            " |  \n",
            " |  ----------------------------------------------------------------------\n",
            " |  Data descriptors defined here:\n",
            " |  \n",
            " |  denominator\n",
            " |      the denominator of a rational number in lowest terms\n",
            " |  \n",
            " |  imag\n",
            " |      the imaginary part of a complex number\n",
            " |  \n",
            " |  numerator\n",
            " |      the numerator of a rational number in lowest terms\n",
            " |  \n",
            " |  real\n",
            " |      the real part of a complex number\n",
            "\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "dir()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "n0YNX9DCzS7W",
        "outputId": "f429fb02-0c22-44e5-b923-4a53d5a5546b"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['In',\n",
              " 'Out',\n",
              " '_',\n",
              " '__',\n",
              " '___',\n",
              " '__builtin__',\n",
              " '__builtins__',\n",
              " '__doc__',\n",
              " '__loader__',\n",
              " '__name__',\n",
              " '__package__',\n",
              " '__spec__',\n",
              " '_dh',\n",
              " '_i',\n",
              " '_i1',\n",
              " '_i2',\n",
              " '_ih',\n",
              " '_ii',\n",
              " '_iii',\n",
              " '_oh',\n",
              " 'exit',\n",
              " 'get_ipython',\n",
              " 'quit',\n",
              " 'x']"
            ]
          },
          "metadata": {},
          "execution_count": 2
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "dir(int)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "VwcD8r1jzdgs",
        "outputId": "9aa6461e-f63b-401b-c81f-efb90a6d4799"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['__abs__',\n",
              " '__add__',\n",
              " '__and__',\n",
              " '__bool__',\n",
              " '__ceil__',\n",
              " '__class__',\n",
              " '__delattr__',\n",
              " '__dir__',\n",
              " '__divmod__',\n",
              " '__doc__',\n",
              " '__eq__',\n",
              " '__float__',\n",
              " '__floor__',\n",
              " '__floordiv__',\n",
              " '__format__',\n",
              " '__ge__',\n",
              " '__getattribute__',\n",
              " '__getnewargs__',\n",
              " '__gt__',\n",
              " '__hash__',\n",
              " '__index__',\n",
              " '__init__',\n",
              " '__init_subclass__',\n",
              " '__int__',\n",
              " '__invert__',\n",
              " '__le__',\n",
              " '__lshift__',\n",
              " '__lt__',\n",
              " '__mod__',\n",
              " '__mul__',\n",
              " '__ne__',\n",
              " '__neg__',\n",
              " '__new__',\n",
              " '__or__',\n",
              " '__pos__',\n",
              " '__pow__',\n",
              " '__radd__',\n",
              " '__rand__',\n",
              " '__rdivmod__',\n",
              " '__reduce__',\n",
              " '__reduce_ex__',\n",
              " '__repr__',\n",
              " '__rfloordiv__',\n",
              " '__rlshift__',\n",
              " '__rmod__',\n",
              " '__rmul__',\n",
              " '__ror__',\n",
              " '__round__',\n",
              " '__rpow__',\n",
              " '__rrshift__',\n",
              " '__rshift__',\n",
              " '__rsub__',\n",
              " '__rtruediv__',\n",
              " '__rxor__',\n",
              " '__setattr__',\n",
              " '__sizeof__',\n",
              " '__str__',\n",
              " '__sub__',\n",
              " '__subclasshook__',\n",
              " '__truediv__',\n",
              " '__trunc__',\n",
              " '__xor__',\n",
              " 'as_integer_ratio',\n",
              " 'bit_count',\n",
              " 'bit_length',\n",
              " 'conjugate',\n",
              " 'denominator',\n",
              " 'from_bytes',\n",
              " 'imag',\n",
              " 'numerator',\n",
              " 'real',\n",
              " 'to_bytes']"
            ]
          },
          "metadata": {},
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "help()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Wrxb443Z0Gpi",
        "outputId": "b67ad8c4-f302-456c-b3ae-596b31224dc8"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\n",
            "Welcome to Python 3.10's help utility!\n",
            "\n",
            "If this is your first time using Python, you should definitely check out\n",
            "the tutorial on the internet at https://docs.python.org/3.10/tutorial/.\n",
            "\n",
            "Enter the name of any module, keyword, or topic to get help on writing\n",
            "Python programs and using Python modules.  To quit this help utility and\n",
            "return to the interpreter, just type \"quit\".\n",
            "\n",
            "To get a list of available modules, keywords, symbols, or topics, type\n",
            "\"modules\", \"keywords\", \"symbols\", or \"topics\".  Each module also comes\n",
            "with a one-line summary of what it does; to list the modules whose name\n",
            "or summary contain a given string such as \"spam\", type \"modules spam\".\n",
            "\n",
            "help> \n",
            "\n",
            "You are now leaving help and returning to the Python interpreter.\n",
            "If you want to ask for help on a particular object directly from the\n",
            "interpreter, you can type \"help(object)\".  Executing \"help('string')\"\n",
            "has the same effect as typing a particular string at the help> prompt.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "o1jbCtUN5c9x"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}